package com.tzinfo.tzt.activity.util;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.tzinfo.tzt.R;
import com.tzinfo.tzt.activity.CarNewsDetailActivity;
import com.tzinfo.tzt.util.Resultmap;

import java.util.List;

/**
 * Created by Administrator on 2014/11/7.
 */
public class FragmentHomeListviewAdapter2 extends BaseAdapter{
    ImageLoader image_loader;

    private Context context;
    private List<Resultmap> data;


    public FragmentHomeListviewAdapter2(Context context,List<Resultmap> data) {
        this.context = context;
        this.data = data;
        image_loader= ImageLoader.getInstance();

    }
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_item_car_information,parent,false);
            holder.TitleextView = (TextView)convertView.findViewById(R.id.item_car_information_title);
            holder.PubdtTextView = (TextView)convertView.findViewById(R.id.item_car_information_pubdt);
            holder.car_information_ll =(LinearLayout)convertView.findViewById(R.id.item_car_information_ll);
            holder.imageView =(ImageView)convertView.findViewById(R.id.item_car_information_imageView);
            convertView.setTag(holder);
        }
        else {
            holder =(ViewHolder)convertView.getTag();
        }
        holder.TitleextView.setText(data.get(position).getTitle().toString());
        holder.PubdtTextView.setText(data.get(position).getPubDT().toString());
        image_loader.displayImage(data.get(position).getPicfile(),holder.imageView);
        holder.car_information_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CarNewsDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("Id", data.get(position).getId());
                intent.putExtras(bundle);
                context.startActivity(intent);
                //              Toast.makeText(context,""+data.get(position).getId(),Toast.LENGTH_SHORT).show();
            }
        });
     //   holder.car_information_ll.setOnClickListener();
        return  convertView;
    }

    class ViewHolder{
        TextView TitleextView;
        TextView PubdtTextView;
        LinearLayout car_information_ll;
        ImageView imageView;
    }
}
